#ifndef _UTILCOMMON_H_
#define _UTILCOMMON_H_

#ifndef _OFF_T_DEFINED
    #define _OFF_T_DEFINED
    typedef long _off_t; 
#endif


#ifdef CPP_NO_VTABLE
#undef CPP_NO_VTABLE
#endif

#if defined(_MSC_VER)
#define CPP_NO_VTABLE __declspec(novtable)
#else
#define CPP_NO_VTABLE
#endif


#if (CPP_COMPILER == CC_MSVC )
	#define __attribute__(x)
#elif (CPP_COMPILER == CC_GCC )

#endif


#if(CPP_COMPILER == CC_MSVC)
	#define _aligned(g)		__declspec(align(g))
#else
	#define _aligned(g)		__attribute__((aligned(g)))
#endif

#define __aligned(g, type) _aligned(g) type


#define	PACK_ONEBYTE		__attribute__((packed))
#define	PACK_EIGHTBYTE		__attribute__((aligned(8))) 


#ifndef MAX_PATH
#define MAX_PATH          260
#endif

//dll 
//__declspec(dllexport)
//so no display 
#ifdef  __GNUC__
#define OS_VISIBILITY_HIDDEN   __attribute__ ((visibility ("hidden")))
#else
#define OS_VISIBILITY_HIDDEN
#endif

//so display 
#ifdef __GNUC__
#define OS_VISIBILITY_DEFAULT __attribute__ ((visibility ("default")))
#else
#define OS_VISIBILITY_DEFAULT
#endif


#ifdef	__GNUC__
#define	_unused	__attribute__ ((__unused__))
#else
#define  _unused 
#endif




#ifdef __cplusplus
	#ifndef EXTERN_C
	#define EXTERN_C   extern "C"
	#endif
	#define offsetofclass(base, derived) ((DWORD_PTR)(static_cast<base*>((derived*)_ATL_PACKING))-_ATL_PACKING)

#else
	#ifndef EXTERN_C
	#define EXTERN_C   extern
	#endif
#endif

#ifndef __cplusplus

#define bool	_Bool
#define false	0
#define true	1

#endif /* __cplusplus */

#define OS_HIDDEN_(type)                        OS_VISIBILITY_HIDDEN type
#define OS_EXTERNAL_VIS_(type)                  OS_VISIBILITY_DEFAULT type

#define OS_HIDDEN                               OS_VISIBILITY_HIDDEN
#define OS_EXTERNAL_VIS                         OS_VISIBILITY_DEFAULT

#undef  IMETHOD_VISIBILITY
#define IMETHOD_VISIBILITY                      OS_VISIBILITY_HIDDEN

#ifdef _MSC_VER

#define OS_STDCALL                              __stdcall
#define OS_IMPORT                               __declspec(dllimport)
#define OS_IMPORT_(type)                        type __declspec(dllimport) __stdcall
#define OS_EXPORT                               __declspec(dllexport)
#define OS_EXPORT_(type)                        type __declspec(dllexport) __stdcall


#define OS_METHOD(type)							EXTERN_C __declspec(dllexport) type __stdcall
#define OS_METHOD_NONSTD(type)					EXTERN_C __declspec(dllexport) type __cdecl


#define OS_CALLBACK_(_type, _name)              _type (__stdcall * _name)
#define OS_EXPORT_STATIC_MEMBER_(type)          type
#define OS_IMPORT_STATIC_MEMBER_(type)          type

#else

#define OS_STDCALL								
#define OS_IMPORT                               NS_EXTERNAL_VIS
#define OS_IMPORT_(type)                        NS_EXTERNAL_VIS_(type)
#define OS_EXPORT                               NS_EXTERNAL_VIS
#define OS_EXPORT_(type)                        NS_EXTERNAL_VIS_(type)

#define OS_METHOD(type)							OS_EXTERNAL_VIS type 
#define OS_METHOD_NONSTD(type)					OS_EXTERNAL_VIS type

#define OS_CALLBACK_(_type, _name)              _type (* _name)
#define OS_EXPORT_STATIC_MEMBER_(type)          NS_EXTERNAL_VIS_(type)
#define OS_IMPORT_STATIC_MEMBER_(type)          NS_EXTERNAL_VIS_(type)

#endif






#ifdef __cplusplus
	#define STDNOTHROW (std::nothrow)
	#define Memory_Allocate new STDNOTHROW
	#ifndef tstring
		#ifdef _UNICODE
			#define tstring std::wstring
		#else	
			#define tstring std::string
		#endif
	#endif

	# define CPP_INLINE inline
#else
	#define Memory_Allocate malloc
	#define STDNOTHROW 
#endif

typedef unsigned char   u_char;
typedef unsigned short  u_short;
typedef unsigned int    u_int;
typedef unsigned long   u_long;


#endif